Skip to content

Refactoring to allow multiple asset selection algorithms - #1577

Open
tsmbland wants to merge 7 commits into
circularity_milpfrom
multi_investment_algorithms_prep
Open

tsmbland wants to merge 7 commits into
circularity_milpfrom
multi_investment_algorithms_prep

Conversation

@tsmbland

@tsmbland tsmbland commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

We want to support multiple different asset selection algorithms. The idea is that we will have different agent "types" which select assets in different ways (this is different to objectives which are used within each algorithm as a way of assessing asset options).

This is just a refactor of the current algorithm to make it possible to easily slot in new algorithms, introducing the concept of an agent type. I've called the current type "competitive", as I believe the algorithm was designed to try to simulate a competitive market. This is in contrast to the "portfolio" type introduced in #1574, in which agents are meant to be a single decision maker in change of a portfolio of assets.

The design decision is to make select_assets the front-end for each algorithm, with any implementation details up to the algorithm (these should be private, although currently some need to be public for the benchmark, unfortunately). This includes making the algorithm in charge of its own debug files. To allow this I had to modify the output module to accept custom_writers.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@tsmbland tsmbland changed the title Multi investment algorithms prep Refactoring to allow multiple investment algorithms Nov 4, 2026
@tsmbland tsmbland changed the title Refactoring to allow multiple investment algorithms Refactoring to allow multiple asset selection algorithms Nov 4, 2026
@tsmbland
tsmbland force-pushed the multi_investment_algorithms_prep branch from 7e8fd94 to 40e4737 Compare November 9, 2026 15:16
@tsmbland
tsmbland marked this pull request as ready for review November 9, 2026 15:45
@tsmbland
tsmbland requested a balanced review from Copilot November 9, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the agent-selection refactor.

No open issues 🎉

What changed in this PR

Refactors asset selection to support multiple agent algorithms, isolating the existing behaviour as competitive and preparing for the portfolio algorithm described in #1574.

Changes:

  • Adds an optional agent_type input, defaulting to competitive, and routes market selection accordingly.
  • Moves competitive selection, appraisal and debug output into a dedicated module.
  • Adds reusable custom debug writers and updates tests, fixtures and benchmark imports.
File Description
tests/​data/​simple/​debug_asset_selection_competitive.csv Adds expected competitive-selection debug output.
src/​simulation/​market.rs Routes asset selection by agent type.
src/​simulation/​investment/​competitive/​optimisation.rs Updates imports for the relocated optimisation code.
src/​simulation/​investment/​competitive/​metrics.rs Relocates appraisal metrics and narrows visibility.
src/​simulation/​investment/​competitive/​debug.rs Owns competitive debug CSV output and its tests.
src/​simulation/​investment/​competitive/​costs.rs Houses competitive appraisal cost calculations.
src/​simulation/​investment/​competitive/​constraints.rs Updates imports for relocated appraisal constraints.
src/​simulation/​investment/​competitive/​coefficients.rs Adjusts coefficient interfaces and helper visibility.
src/​simulation/​investment/​competitive.rs Encapsulates competitive selection and related tests.
src/​simulation/​investment.rs Retains shared utilities and exposes the competitive module.
src/​output.rs Adds lazily created custom debug writers and tests.
src/​input/​agent/​search_space.rs Updates test agents with the default agent type.
src/​input/​agent.rs Parses optional agent types and tests defaults and validation.
src/​fixture.rs Updates agent fixtures and removes the shared appraisal fixture.
src/​agent.rs Defines AgentType and adds it to agents.
schemas/​input/​agents.yaml Documents the optional agent_type field.
benches/​assets.rs Updates imports to the competitive module.

Review effort: Balanced

@tsmbland

tsmbland commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

@alexdewar Again, you missed all the conversations I had with Adam about this (mostly on Teams and not captured in issues). Happy to discuss further if you need more explanation.

@tsmbland
tsmbland requested a review from alexdewar November 9, 2026 15:52
@tsmbland
tsmbland added this pull request to stack #1584 November 10, 2026 11:27
tsmbland and others added 7 commits November 10, 2026 11:53
Pure move: appraisal.rs becomes competitive/metrics.rs and the appraisal
submodules move alongside it, in preparation for supporting multiple asset
selection algorithms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…module

select_best_assets, its helpers and the candidate/tranche logic move from
investment.rs and market.rs into investment/competitive.rs. No behaviour
change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Option building and process exclusion move inside the algorithm, so
select_assets_for_single_market only computes demand portions and limits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Allows modules such as asset selection algorithms to own their debug files,
which are created lazily on first write.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove appraisal-specific code from the output module. The competitive
algorithm now writes debug_asset_selection_competitive.csv and
debug_asset_selection_competitive_time_slices.csv via DataWriter::write_debug_rows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The optional agent_type column selects the asset selection algorithm for each
agent. Currently the only option is `competitive` (the default), so existing
models are unaffected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tsmbland
tsmbland force-pushed the multi_investment_algorithms_prep branch from 3db7b64 to c241bd6 Compare November 10, 2026 11:53
@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.77378% with 32 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (circularity_milp@316b17b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/simulation/investment/competitive.rs 91.34% 24 Missing and 1 partial ⚠️
src/output.rs 80.00% 1 Missing and 4 partials ⚠️
src/simulation/investment/competitive/debug.rs 96.22% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##             circularity_milp    #1577   +/-   ##
===================================================
  Coverage                    ?   89.21%           
===================================================
  Files                       ?       63           
  Lines                       ?     9209           
  Branches                    ?     9209           
===================================================
  Hits                        ?     8216           
  Misses                      ?      676           
  Partials                    ?      317           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tsmbland
tsmbland removed this pull request from stack #1584 November 10, 2026 15:58
@tsmbland
tsmbland added this pull request to stack #1588 November 10, 2026 16:00
@tsmbland
tsmbland removed this pull request from stack #1588 November 11, 2026 16:29
@tsmbland
tsmbland added this pull request to stack #1594 November 11, 2026 16:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants